<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="format-detection" content="telephone=no">
        
        <title>内部优惠券</title>
        
        <link rel="stylesheet" href="css/coupon.css?t=201611301751" />
    </head>
    <body id="coupon" v-cloak>
    	<!--发券提示-->
		<div class="coupon-tips"><template v-if="timeRetFlag!='0'">您本月已发优惠券<span> {{sendTimes}}</span>张，还可再发<span> {{remainTimes}}</span>张</template></div>
		<!--搜索栏-->
		<div class="coupon-search" v-show="searchShow">
			<div class="ipt-box">
				<span class="sprites i-search"></span>
				<input class="ipt" type="text" v-model="iptVal" placeholder="输入商品名称快速查找可用券" @click="goUrl" readonly="readonly" />
				<a href="javascript:;" class="sprites i-close" v-show="iptVal!=''" @click="iptVal=''"></a>
			</div>
		</div>
		<!--优惠券列表-->
		<div class="coupon-list" :class="{'pt':!searchShow}" v-if="retFlag!='0' && itemsLen!=0">
			<div class="item" v-for="item in items">
				<a class="lt" href="javascript:;" @click="viewGoods(item)">
					<p class="price">&yen;<span>{{parseInt(item.couponValue)}}</span></p>
					<p class="view"><span>可用商品</span><span class="sprites i-activity-nor"></span></p>
				</a>
				<a class="rt" href="javascript:;" @click="viewDetail(item)">
					<div class="name">{{item.couponTypeTxt}}</div>
					<div class="explain">{{item.activityName}}</div>
					<div class="tips">{{item.couponRule}}</div>
				</a>
				<a class="btn-send" href="javascript:;" @click="sendCoupon(item)">立即发券</a>
			</div>
		</div>
		<!--暂无可发的优惠券-->
		<div class="no-data" v-else>
			<div class="icon-nodata"></div>
			<div class="text">暂无可发的优惠券</div>
		</div>
		<!--查看发券记录-->
		<a class="btn-record" href="javascript:;" @click="sendRecord"><span>查看发券记录</span><span class="sprites i-btn-arrow"></span></a>
		
		<script src="js/zepto.min.js" type="text/javascript"></script>
		<script src="js/vue.min.js" type="text/javascript"></script>
		<script src="js/vue-resource.min.js" type="text/javascript"></script>
		<script src="js/common.js?t=201611301751" type="text/javascript"></script>
		<script src="js/geo.js" type="text/javascript"></script>
		<script type="text/javascript">
			var vm = new Vue({
                el: '#coupon',
                data: {
	                items: [],
	                itemsLen:null,
	                sendTimes:"",
	                remainTimes:"",
	                timeRetFlag:"",
	                iptVal: "",
	                retFlag:null,
	                
	                cityCode: "9173",
	                mdmCityCode: "000001000173",
	                
	                searchShow: false,
	                
                    err: false,
                    errCtt: ""
                },
                computed: {
                    
                },
                methods: {
                	goUrl: function(){
                    	location.href = "search_coupon.html?cityCode=" + this.cityCode + "&mdmCityCode=" + this.mdmCityCode;
                   	},
                	viewDetail: function(item){
                		if(this.cityCode!=""){
                			location.href = "send_coupon_detail.html?couponRuleId=" + item.couponRuleId + "&activityName=" + encodeURIComponent(item.activityName) + "&couponRule=" + encodeURIComponent(item.couponRule) + "&couponTypeTxt=" + encodeURIComponent(item.couponTypeTxt) + "&couponValue=" +encodeURIComponent(item.couponValue) + "&productsTxt=" + encodeURIComponent(item.productsTxt) + "&storesTxt=" + encodeURIComponent(item.storesTxt) + "&useGuide=" + encodeURIComponent(item.useGuide) + "&cityCode=" + this.cityCode + "&mdmCityCode=" + this.mdmCityCode;
                		}
                   	},
                	sendCoupon: function(item){
                		location.href = "send_coupon.html?activityId=" + encodeURIComponent(item.activityId) + "&securityKey=" + item.securityKey + "&couponValue=" + item.couponValue + "&couponTypeTxt=" + encodeURIComponent(item.couponTypeTxt) + "&couponRule=" + encodeURIComponent(item.couponRule) + "&activityName=" + encodeURIComponent(item.activityName);
                    },
                	sendRecord: function(){
                    	location.href = "send_coupon_record.html";
                   	},
                   	viewGoods: function(item){
                   		if(this.cityCode!=""){
                    		location.href = "view_goods.html?couponRuleId=" + item.couponRuleId + "&cityCode=" + this.cityCode + "&mdmCityCode=" + this.mdmCityCode + "&couponRule=" + item.couponRule + "&couponValue=" +item.couponValue;
                    	}
                   	},
                   	searchUrl: function(){
                   		if(this.iptVal!="" && this.cityCode!="") {
                   			location.href = "search_coupon.html?keyword=" + this.iptVal + "&cityCode=" + this.cityCode + "&mdmCityCode=" + this.mdmCityCode;
                   		}
                    }
                },
                ready: function(){
                	//调用定位
					Wap.Geo(function(meta){
						if(meta != null && meta.cityNo){
							vm.cityCode = meta.cityNo;
							vm.mdmCityCode = "00000"+meta.mdmCityNo;
						}
					});
					
                	this.$http.post(DI.queryRemainTimes, {
						
					}).then(function(res) {
						if(res!=null && res.data.idsIntercepted==true){
							location.href = DI.login + "?redirectUrl=" + location.href;
						    return;
						}
						var result = res.data;
						if(result.retFlag!="0") {
							vm.sendTimes = result.data.sendTimes;
							vm.remainTimes = result.data.remainTimes;
							vm.timeRetFlag = result.retFlag;
						} else {
							
						}
		
					}, function(req) {
		
					});
					
                	this.$http.post(DI.queryCouponList, {
						
					}).then(function(res) {
						if(res!=null && res.data.idsIntercepted==true){
							location.href = DI.login + "?redirectUrl=" + location.href;
						    return;
						}
						var result = res.data;
						if(result.retFlag!="0") {
							vm.items = result.data;
							vm.itemsLen = result.data.length;
							vm.retFlag = result.retFlag;
						} else {
							
						}
		
					}, function(req) {
		
					});
                }
            });
		</script>
    </body>
</html>